package tech.aistar.mapper;

import org.apache.ibatis.annotations.*;
import tech.aistar.entity.House;

import javax.persistence.criteria.CriteriaBuilder;
import java.util.Date;
import java.util.List;

public interface HouseMapper {
        @Select("select * from house")
        List<House> selectAll();




    @Select("select * from house where rent_type='合租' and house_state='待出租'")
    List<House> selectcount();


        @Insert("insert into house values(agentId,landlordId,houseEvaluate," +
                "landlordRequire,propertyOwnershipCertificate,houseType,area," +
                "floor,parkPlace,tenancy,orientate,region,rentType,houseState," +
                "rentMoney,doorplate,residentialQuarters,houseIdentity,imageUrl)")
        void insert(House house);

        @Select("select id from house where doorplate=#{doorplate} and residential_quarters=#{residentialQuarters}")
        Integer selectDoorPlate(@Param("doorplate") String doorplate,@Param("residentialQuarters") String residentialQuarters);

        @Select("select id from house where agent_id=#{agentId} and landlord_id=#{landlordId} and house_evaluate=#{houseEvaluate}" +
                "                and landlord_require=#{landlordRequire} and property_ownership_certificate=#{propertyOwnershipCertificate}" +
                "                and house_type=#{houseType} and area=#{area} and floor=#{floor}" +
                "                and park_place=#{parkPlace} and tenancy=#{tenancy} and orientate=#{orientate}" +
                "                and region=#{region} and rent_type=#{rentType} and house_state=#{houseState}" +
                "                and rent_money=#{rentMoney}")
        Integer selectHouseId(@Param("agentId") Integer agentId, @Param("landlordId") Integer landlordId, @Param("houseEvaluate") String houseEvaluate, @Param("landlordRequire") String landlordRequire, @Param("propertyOwnershipCertificate")
                String propertyOwnershipCertificate, @Param("houseType") String houseType, @Param("area") String area, @Param("floor") Integer floor, @Param("parkPlace")
                                      String parkPlace, @Param("tenancy") String tenancy, @Param("orientate") String orientate, @Param("region") String region, @Param("rentType")
                                      String rentType, @Param("houseState") String houseState, @Param("rentMoney") Double rentMoney);


        @Update("update house set agent_id=#{agentId},landlord_id=#{landlordId},house_evaluate=#{houseEvaluate}" +
                ",landlord_require=#{landlordRequire},property_ownership_certificate=#{propertyOwnershipCertificate}" +
                ",house_type=#{houseType},area=#{area},floor=#{floor}" +
                ",park_place=#{parkPlace},tenancy=#{tenancy},orientate=#{orientate}" +
                ",region=#{region},rent_type=#{rentType},house_state=#{houseState}  where id=#{Id}")
        void  updateByPrimaryKey(House house);

        @Delete("delete from house where id=#{Id}")
        void deleteByPrimaryKey(Integer id);



    //    @Select("select * from house where house_type=#{value}")
        List<House> findByHouseType(String str);


            @Select("select * from house where id=#{Id}")
        List<House> findById(Integer integer);

        @Select("select * from house where id=#{Id}")
        House selectById(Integer integer);

            //学生
            @Select("select * from house where rent_type='学生'")
        List<House> studentAll();

            //地区
            @Select("select * from house where region=#{value}")
        List<House> regionAll(String lab);

        //搜索栏和下拉框
        List<House> searchAll(@Param("str") String str, @Param("lab") String lab);

        //搜索栏,下拉框,复选框
        List<House> searchStudentAll(@Param("str") String str, @Param("lab") String lab, @Param("min") Integer min, @Param("max") Integer max);

        //最终所有条件
        List<House> finalSearch(@Param("lab") String lab, @Param("min") String min, @Param("max") String max, @Param("type") String type, @Param("chao") String chao);


        //白领
    List<House>  whiteFindByHouseType(String str);

    @Select("select * from house where id=#{Id},rent_type=#{rent_type}")
    List<House> FindById(Integer integer);

    @Select("select * from house where id=#{Id}")
    House whiteSelectById(Integer integer);

    @Select("select * from house where rent_type='白领'")
    List<House> whiteAll();

    List<House> whiteSearchAll(@Param("str") String str, @Param("lab") String lab);

    List<House> finalWhiteSearch(@Param("lab") String lab, @Param("min") String min, @Param("max") String max, @Param("type") String type, @Param("chao") String chao);


    //合租
    List<House> finalHeSearch(@Param("lab") String lab, @Param("min") String min, @Param("max") String max, @Param("type") String type, @Param("chao") String chao);

    //合租 - 身份
    List<House> findIdentity(@Param("lab") String lab, @Param("identity") String identity, @Param("min") String min, @Param("max") String max, @Param("type") String type, @Param("chao") String chao);

    //整租
    List<House> finalZhengSearch(@Param("lab") String lab, @Param("min") String min, @Param("max") String max, @Param("type") String type, @Param("chao") String chao);

    //整租 - 身份
    List<House> findZhengIdentity(@Param("lab") String lab, @Param("identity") String identity, @Param("min") String min, @Param("max") String max, @Param("type") String type, @Param("chao") String chao);


    //环境 - 类型 - 白领
    List<House> houseFacility(
            @Param("greenery") String green, @Param("traffic") String traffic, @Param("shop") String shop, @Param("school") String school, @Param("fridge") String fridge,
            @Param("tv") String tv, @Param("wash") String wash, @Param("geyser") String geyser, @Param("air") String air, @Param("broad") String broad,
            @Param("sofa") String sofa, @Param("bed") String bed, @Param("heat") String heat, @Param("wardrobe") String wardrobe, @Param("cook") String cook,
            @Param("bath") String bath, @Param("balcony") String balcony, @Param("lock") String lock, @Param("hood") String hood, @Param("stove") String stove);


    //环境 - 类型 - 学生
    List<House> houseStudentFacility(
            @Param("greenery") String green, @Param("traffic") String traffic, @Param("shop") String shop, @Param("school") String school, @Param("fridge") String fridge,
            @Param("tv") String tv, @Param("wash") String wash, @Param("geyser") String geyser, @Param("air") String air, @Param("broad") String broad,
            @Param("sofa") String sofa, @Param("bed") String bed, @Param("heat") String heat, @Param("wardrobe") String wardrobe, @Param("cook") String cook,
            @Param("bath") String bath, @Param("balcony") String balcony, @Param("lock") String lock, @Param("hood") String hood, @Param("stove") String stove);


    //环境 - 类型 - 合租
    List<House> houseHeFacility(
            @Param("greenery") String green, @Param("traffic") String traffic, @Param("shop") String shop, @Param("school") String school, @Param("fridge") String fridge,
            @Param("tv") String tv, @Param("wash") String wash, @Param("geyser") String geyser, @Param("air") String air, @Param("broad") String broad,
            @Param("sofa") String sofa, @Param("bed") String bed, @Param("heat") String heat, @Param("wardrobe") String wardrobe, @Param("cook") String cook,
            @Param("bath") String bath, @Param("balcony") String balcony, @Param("lock") String lock, @Param("hood") String hood, @Param("stove") String stove);


    //设施环境 -全 - 合租
    List<House> houseAllHeFacility(
            @Param("lab") String lab, @Param("identity") String identity, @Param("min") String min, @Param("max") String max, @Param("type") String type, @Param("chao") String chao,
            @Param("greenery") String green, @Param("traffic") String traffic, @Param("shop") String shop, @Param("school") String school, @Param("fridge") String fridge,
            @Param("tv") String tv, @Param("wash") String wash, @Param("geyser") String geyser, @Param("air") String air, @Param("broad") String broad,
            @Param("sofa") String sofa, @Param("bed") String bed, @Param("heat") String heat, @Param("wardrobe") String wardrobe, @Param("cook") String cook,
            @Param("bath") String bath, @Param("balcony") String balcony, @Param("lock") String lock, @Param("hood") String hood, @Param("stove") String stove);

    @Select("select * from house where rent_type='合租' and house_state='待出租'")
    List<House> selectHe();

    //设施环境 -全 - 整租
    List<House> houseAllZhengFacility(
            @Param("lab") String lab, @Param("identity") String identity, @Param("min") String min, @Param("max") String max, @Param("type") String type, @Param("chao") String chao,
            @Param("greenery") String green, @Param("traffic") String traffic, @Param("shop") String shop, @Param("school") String school, @Param("fridge") String fridge,
            @Param("tv") String tv, @Param("wash") String wash, @Param("geyser") String geyser, @Param("air") String air, @Param("broad") String broad,
            @Param("sofa") String sofa, @Param("bed") String bed, @Param("heat") String heat, @Param("wardrobe") String wardrobe, @Param("cook") String cook,
            @Param("bath") String bath, @Param("balcony") String balcony, @Param("lock") String lock, @Param("hood") String hood, @Param("stove") String stove);

    @Select("select * from house where rent_type='整租' and house_state='待出租'")
    List<House> selectZheng();

    //环境 - 类型 - 学生
    List<House> houseZhengFacility(
            @Param("greenery") String green, @Param("traffic") String traffic, @Param("shop") String shop, @Param("school") String school, @Param("fridge") String fridge,
            @Param("tv") String tv, @Param("wash") String wash, @Param("geyser") String geyser, @Param("air") String air, @Param("broad") String broad,
            @Param("sofa") String sofa, @Param("bed") String bed, @Param("heat") String heat, @Param("wardrobe") String wardrobe, @Param("cook") String cook,
            @Param("bath") String bath, @Param("balcony") String balcony, @Param("lock") String lock, @Param("hood") String hood, @Param("stove") String stove);




    @Insert("insert into house(agent_id,landlord_id,house_evaluate,landlord_require,property_ownership_certificate,house_type,area,floor,park_place,tenancy,orientate,region,house_state,rent_type,rent_money,house_identity,doorplate,residential_quarters) " +
            "value(#{agentId},#{landlordId},#{houseEvaluate},#{landlordRequire},#{propertyOwnershipCertificate},#{houseType},#{area},#{floor},#{parkPlace},#{tenancy},#{orientate},#{region},#{houseState},#{rentType},#{rentMoney},#{houseIdentity},#{doorplate},#{residentialQuarters})")
    int insertHouse(House house);

    @Insert("insert into house(agent_id,landlord_id,house_evaluate,landlord_require,property_ownership_certificate,house_type,area,floor,park_place,tenancy,orientate,region,house_state,rent_type,rent_money,house_identity,doorplate,residential_quarters,image_url) " +
            "value(#{agentId},#{landlordId},#{houseEvaluate},#{landlordRequire},#{propertyOwnershipCertificate},#{houseType},#{area},#{floor},#{parkPlace},#{tenancy},#{orientate},#{region},#{houseState},#{rentType},#{rentMoney},#{houseIdentity},#{doorplate},#{residentialQuarters},#{imageUrl})")
    int insertHouse2(House house);



    @Select("select * from house where id=#{houseId}")
    House selectByhouseId(Integer houseId);


    @Select("select * from house where landlord_id=#{landlordId}")
    List<House> selectBylandlordId(Integer landlordId);

    @Delete("delete from house where id=#{Id}")
    int deleteById(Integer id);

    @Select("select * from house where agent_id=#{agentId}")
    List<House> selectByagentId(Integer agentId);


    @Select("select agent_id from house where id=#{Id}")
    Integer selectagentByhouseId(Integer integer);

    @Select("select * from house where agent_id=#{agentId} and house_state='待发布'")
    List<House> selectByagentIds(Integer agentId);

    @Select("select * from house where rent_type='整租' and house_state='待出租' limit 6")
    List<House> selectHouseLimit();

    @Update("update house set house_state='待出租' where id=#{Id}")
    int updateStateById(Integer id);

@Select("select rent_type from house where id=#{id}")
    String selectRentTypeById(Integer id);
}
